<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>华胜后台管理</title>
		<link rel="stylesheet" type="text/css" href="css/unified.css">
		<script src="plugins/layui/layui.js"></script>
		<style type="text/css">
			.addbtn {
				/*background-color: #1E9FFF*/
			}
			
			.layui-table-view .layui-table td,
			.layui-table-view .layui-table th {
				padding: 0
			}
			
			.layui-table-view .layui-table[lay-size=lg] .layui-table-cell {
				height: 40px;
				line-height: 40px;
			}
			
			.layui-col-md6,
			.layui-col-md4,
			.layui-col-md12 {
				padding: 0 10px;
			}
			
			.layui-form-pane .layui-form-label {
				width: 134px;
			}
			
			.layui-form-pane .layui-input-block {
				margin-left: 134px;
			}
		</style>
	</head>

	<body>
		<div class="breadcrumbnav">
			<span class="layui-breadcrumb " lay-separator="·">
          <a ><cite>首页</cite></a>
          <a ><cite>门店管理</cite></a>
        </span>
		</div>
		<div class="kit-doc">
			<!-- 标题 -->

			<div class="kit-doc-title">
				<fieldset>
					<legend>
						<a name="blockquote">门店</a>
					</legend>
				</fieldset>
			</div>
			<!-- 概述 -->
			<div class="boderbox">
				<div class="rowtop">
					<button class="layui-btn addbtn openwinbtn" data-method="addmang">
                    添加+
                </button>
                <button class="layui-btn addbtn openwinbtn layui-bg-blue hidediv" id="yeschoice"  data-method="yeschoice">确认选择</button>
					<!--<form class="layui-form searchform" action="" id="comSearchForm">
                        <select name="city" lay-verify="">
                            <option value="oderid">条码</option>
                            <option value="name">名称</option>
                        </select>
                        <div class="layui-input-inline">
                            <input type="text" name="text" required lay-verify="required" placeholder="输入关键字" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-btn-group">
                            <button class="layui-btn">搜索</button>
                            <button class="layui-btn layui-btn-normal">重置</button>
                        </div>
                    </form>-->
				</div>

				<div class="layui-tab-content notab">
					<div class="layui-tab-item layui-show">
						<table class="layui-table " lay-filter="table100" id="SMemttable"></table>
					</div>
				</div>

				<script id="addBox" type="text/html">
					<div class=" layui-layer-wrap">
						<form class="layui-form layui-form-pane" action="" id="addform">

							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">店铺名称</label>
									<div class="layui-input-block">
										<input type="text" name="shopName" autocomplete="off" placeholder="" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">主营</label>
									<div class="layui-input-block">
										<input type="text" name="mainProducts" autocomplete="off" placeholder="" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">地区</label>
									<div class="layui-input-block">
										<input type="text" name="region" autocomplete="off" lay-verify="required" placeholder="" class="layui-input">

									</div>
								</div>
							</div>

							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">营业执照编号</label>
									<div class="layui-input-block">
										<input type="text" name="businessLicense" autocomplete="off" lay-verify="required" placeholder="" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">注册日期</label>
									<div class="layui-input-block">
										<input type="text" id="createTime" name="registerTime" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">商户名称</label>
									<div class="layui-input-block">
										<input type="text" name="merchantName" autocomplete="off" lay-verify="required" placeholder="" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">负责人</label>
									<div class="layui-input-block">
										<input type="text" name="leadingOfficial" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">商户账户名</label>
									<div class="layui-input-block">
										<input type="text" name="merchantAccount" lay-verify="required" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">商户密码</label>
									<div class="layui-input-block">
										<input type="text" name="password" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>

							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">商户电话</label>
									<div class="layui-input-block">
										<input type="text" name="merchantPhone" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">身份证编号</label>
									<div class="layui-input-block">
										<input type="text" name="identifyId" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12  layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">商户支付宝ID</label>
									<div class="layui-input-block">
										<input type="text" name="alipay" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12  layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">商户微信ID</label>
									<div class="layui-input-block">
										<input type="text" name="wechatpay" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
								<div class="layui-form-item">
									<label class="layui-form-label">税号</label>
									<div class="layui-input-block">
										<input type="text" name="taxNumber" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
								<div class="layui-form-item">
									<label class="layui-form-label">描述分数</label>
									<div class="layui-input-block">
										<input type="text" name="describeFraction" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
								<div class="layui-form-item">
									<label class="layui-form-label">服务评分</label>
									<div class="layui-input-block">
										<input type="text" name="serviceFraction" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
							<div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
								<div class="layui-form-item">
									<label class="layui-form-label">物流评分</label>
									<div class="layui-input-block">
										<input type="text" name="logisticsFraction" autocomplete="off" class="layui-input" placeholder="">
									</div>
								</div>
							</div>
						</form>
						<div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
							<div class="layui-form-item">
								<form action="#" method="post" enctype="multipart/form-data" target="framFile1" class="updataform1 imgbox">
									<input type="button" class="layui-btn-primary imgbtn" value="选择头像" />
									<input type="file" class=" imgfile" name="files" multiple="true" value="选择文件" accept="image/*" onchange="xmTanUploadImg(this)" />
									<input type="button" class="layui-btn upNewimg" value="确认上传" style="" />

									<img id="xmTanImg" class="xmTanImg" />
								</form>

							</div>
						</div>
					</div>

				</script>
				<!--图片的iframe-->
				<iframe id="framFile" name="framFile" style="display: none;"></iframe>
				<iframe id="framFile1" name="framFile1" style="display: none;"></iframe>
				<script src="../js/jquery-3.2.1.min.js"></script>
				<script src="js/allajax.js"></script>
				<script>
					var pcount = 0; //总页数
					layui.use(['layer', 'form', 'element', 'table', 'laydate', 'laypage'], function() {
						var layer = layui.layer,
							form = layui.form,
							element = layui.element,
							table = layui.table,
							laydate = layui.laydate,
							laypage = layui.laypage;
						laydate.render({
							elem: '#createTime' //指定元素
						});
						$('.openwinbtn').on('click', function() {
							var othis = $(this),
								method = othis.data('method');
							active[method] ? active[method].call(this, othis) : '';
						});

						var active = {
							//                          弹出框事件
							addmang: function() {
								layer.open({
									type: 1,
									skin: 'layui-layer-molv',
									title: '新增门店',
									area: ['850px', '750px'],
									content: $("#addBox").html(),
									skin: 'demo-class',
									btn: ["确认修改", "关闭"],
									yes: function(index, layero) {
										//按钮1的回调
										if(imgdata == undefined) {
											layer.msg("请选择图片上传");
										} else {
											var thisdata = $("#addform").serializeJson();
											thisdata.classifyImage = imgdata;
											console.log(thisdata);
											AjaxPostFn('system/bizmerchantinfo/insert', JSON.stringify(thisdata), function(jsonData) {

												if(jsonData.htmlState.status == 200) {
													layer.msg("增加成功");
													location.reload();
												}
											})
										}

									},
									btn2: function(index, layero) {
										//按钮2的回调
									},
									cancel: function() {
										//右上关闭的回调
									},
									success: function() {
										form.render();
										$(".upNewimg").val("点击上传");

										laydate.render({
											elem: '#createTime',
											type: 'datetime'
										});
										$(".updataform1").attr("action",AllUrl+"api/qiniu/update")
										$(".updataform1").submit();
										//图片上传form的submit
										$(".upNewimg").click(function() {
											$(".updataform1").submit();

										})

										//图片上传的frame的窗口
										var framFile1 = document.getElementById('framFile1');
										framFile1.onload = function() {
											console.log("最新窗口点击");
											imgdata = framFile1.contentWindow.document.getElementsByTagName("pre")[0].innerHTML;
											imgdata = JSON.parse(imgdata).dataResultObj[0];
											console.log(imgdata);
											if(imgdata == null) {
												$(".upNewimg").val("点击上传");
												//	                    	layer.msg("上传失败，请选择头像重新上传！");
											} else {
												$(".upNewimg").val("上传成功");
											}

										}
									}
								})
							}
						}

						var tableArray = new Array();
						SMListFn(1);

						function SMListFn(curr, limit) {
							AjaxPostFn('system/bizmerchantinfo/select?page=' + curr + '&pagesize=10', "{}", function(jsonData) {
								pcount = jsonData.pageInfo.total;

								$.each(jsonData.pageInfo.list, function(i, obj) {
										//                      console.log(JSON.stringify(obj))
										//                      if(obj.bizRepositoryOut != null){
										tableArray.push({
											"id": obj.id,
											"operation": '<a class="layui-btn layui-btn " lay-event="updataThis" >上传logo</a> <a class="layui-btn layui-btn-danger " lay-event="delThis" >删除</a> ',
											"shopName": obj.shopName,
											"region": obj.region,
											"merchantNumber": obj.merchantNumber,
											"alipay": obj.alipay,
											"merchantAccount": obj.merchantAccount,
											"password": "123456",
											"merchantName": obj.merchantName,
											"leadingOfficial": obj.leadingOfficial,
											"describeFraction": obj.describeFraction,
											"serviceFraction": obj.serviceFraction,
											"logisticsFraction": obj.logisticsFraction,
											"registerTime": getMyDate(obj.registerTime),
											"merchantPhone": obj.merchantPhone,
											"alipay": null,
											"wechatpay": obj.wechatpay,
											"identifyId": obj.identifyId,
											"businessLicense": obj.businessLicense,
											"taxNumber": obj.taxNumber,
											"mainProducts": obj.mainProducts,
											"updatamerchantLogoUrl": "<img src='" + IMGUrl + "" + obj.merchantLogoUrl + "' class='classifyimg'/ >"

										});
									})
									//                  console.log(tableArray)
									//展示已知数据
								table.render({
									elem: '#SMemttable',
									cols: [
										[ //标题栏
											{
												type: 'numbers',
												fixed: 'left',
												title: '行号'
											}, {
												field: 'id',
												minWidth: '0%',
												width: '0%',
												type: 'space',
												style: 'display:none'
											}, {
												field: 'operation',
												width: 200,
												title: '操作'
											}, {
												field: 'merchantNumber',
												width: 200,
												title: '商户编号',

											}, {
												field: 'shopName',
												width: 200,
												title: '店铺名称' + modDot,
												edit: 'text'
											}, {
												field: 'mainProducts',
												width: 100,
												title: '主营' + modDot,
												edit: 'text'
											}, {
												field: 'region',
												width: 150,
												title: '地区' + modDot,
												edit: 'text'
											}, {
												field: 'updatamerchantLogoUrl',
												width: 100,
												title: '商户logo'
											}, {
												field: 'businessLicense',
												width: 200,
												title: '营业执照编号' + modDot,
												edit: 'text'
											}, {
												field: 'merchantName',
												width: 150,
												title: '商户名称' + modDot,
												edit: 'text'
											}, {
												field: 'leadingOfficial',
												width: 150,
												title: '负责人' + modDot,
												edit: 'text'
											}, {
												field: 'merchantAccount',
												width: 150,
												title: '商户账户名' + modDot,
												edit: 'text'
											}, {
												field: 'password',
												width: 100,
												title: '商户密码' + modDot,
												edit: 'text'
											}, {
												field: 'describeFraction',
												width: 200,
												title: '描述分数' + modDot,
												edit: 'text'
											}, {
												field: 'serviceFraction',
												width: 200,
												title: '服务评分' + modDot,
												edit: 'text'
											}, {
												field: 'logisticsFraction',
												width: 200,
												title: '物流评分' + modDot,
												edit: 'text'
											}, {
												field: 'registerTime',
												width: 200,
												title: '注册日期'
											}, {
												field: 'merchantPhone',
												width: 200,
												title: '商户电话' + modDot,
												edit: 'text'
											}, {
												field: 'identifyId',
												width: 200,
												title: '身份证编号' + modDot,
												edit: 'text'
											}, {
												field: 'alipay',
												width: 200,
												title: '商户支付宝ID' + modDot,
												edit: 'text'
											}, {
												field: 'wechatpay',
												width: 200,
												title: '商户微信ID' + modDot,
												edit: 'text'
											}, {
												field: 'taxNumber',
												width: 200,
												title: '税号' + modDot,
												edit: 'text'
											}
										]
									],
									data: tableArray,
									size: 'lg',
									even: true,

									page: true, //是否显示分页
									done: function(res, curr, count) {
										console.log(jsonData.pageInfo.total);
										//图片点击放大
										TopimgFn();
										laypage.render({
											elem: 'layui-table-page1' //注意，这里的 test1 是 ID，不用加 # 号
												,
											count: pcount //数据总数，从服务端得到
												,
											curr: location.hash.replace('#!fenye=', '') //获取起始页
												,
											hash: 'fenye' //自定义hash值
												,
											pages: jsonData.pageInfo.pages,
											jump: function(obj, first) {
												//obj包含了当前分页的所有参数，比如：
												console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
												console.log(obj.limit); //得到每页显示的条数

												//首次不执行
												if(!first) {
													//do something
													SMListFn(obj.curr);
												}
											}
										});

									}
								});

							});

						} //listFN结束
						table.on('tool(table100)', function(obj) {
							var data = obj.data;
							if(obj.event === 'delThis') {
								layer.confirm('真的删除行么', function(index) {
									//                                      system/bizmerchantinfo/deletebyid
									AjaxPostFn('system/bizmerchantinfo/deletebyid', "{'id':'" + data.id + "'}", function(jsonData) {
										if(jsonData.htmlState.status == 200) {
											layer.msg("修改成功");
											layer.closeAll();
										}

									});
									obj.del();
									layer.close(index);

								})

							} else if(obj.event === 'updataThis') {
								//上传主图
								layer.open({

									title: '上传图片',
									area: ['390px', '260px'],
									shade: 0,
									maxmin: true,
									btn: ['上传'],
									content: ' <form action="'+AllUrl+'api/qiniu/update" method="post"  enctype="multipart/form-data" target="framFile"  class="updataform"  >  <input type="file" name="files"  multiple="true" class="file_upload" />  </form>',
									yes: function() {
										thisid = data.merchantNumber;
										$(".updataform").submit();

									},
									success: function(layero) {}
								});
								var thisid = 1;
								var framFile = document.getElementById('framFile');
								var imgdata;
								framFile.onload = function() {
										imgdata = framFile.contentWindow.document.getElementsByTagName("pre")[0].innerHTML;
										imgdata = JSON.parse(imgdata).dataResultObj[0];
										console.log(imgdata)

										AjaxPostFn('system/bizmerchantinfo/update', "{'merchantNumber':'" + thisid + "','merchantLogoUrl':'" + imgdata + "'}", function(jsonData) {
											console.log(jsonData)
											if(jsonData.htmlState.status == 200) {
												layer.msg("修改成功");
												layer.closeAll();
												location.reload();
											}

										});

									} //上传主图结束

							}
						}); //表格内按钮监听结束

						//监听单元格编辑
						table.on('edit(table100)', function(obj) {
							var value = obj.value //得到修改后的值
								,
								data = obj.data //得到所在行所有键值
								,
								field = obj.field; //得到字段
							AjaxPostFn('system/bizmerchantinfo/update', data, function(jsonData) {
								if(jsonData.htmlState.status == 200) {
									layer.msg("修改成功");
									layer.closeAll();
								}

							});

						});

					});
				</script>
			</div>
			<!-- 概述 end-->
		</div>
	</body>

</html>